import { defineConfig } from 'vite'
import { resolve } from 'path';
import createVitePlugins from './plugin'

// 重定向路径
function pathResolve(dir: string) {
  return resolve(__dirname, '.', dir);
}

const alias: Record<string, string> = {
  '~': pathResolve('./'),
  '@com': pathResolve('./src/components'),
  '@': pathResolve('./src')
}

export default defineConfig(({ command }) => {
  return {
    mode: command === 'serve' ? 'development' : 'production',
    envDir: './envs',
    envPrefix: 'VITE_',
    plugins: createVitePlugins(),
    resolve: {
      alias,
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
    },
    server: {
      port: 8080,
      host: true
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "@/assets/style/dark.scss" as *;`,
          javascriptEnabled: true
        },
      },
    }
  }
})
